// 窗体格式
function windowType(obj) {
    var arr = [];
    if (!obj) {
        return '';
    }
    for (var key in obj) {
        arr.push(key + '=' + obj[key]);
    }
    return '?' + arr.join('&');
}

// get函数
function getData(url, obj, fun) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url + windowType(obj));
    xhr.send();
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            if (xhr.status == 200 && xhr.status < 300 || xhr.status == 304) {
                var data = JSON.parse(xhr.responseText);
                fun(data);
            }
        }
    }
}

// post函数
function postData(url, obj, fun) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', url);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(JSON.stringify(obj));
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            if (xhr.status == 200 && xhr.status < 300 || xhr.status == 304) {
                var data = JSON.parse(xhr.responseText);
                fun(data);
            }
        }
    }
}